import request from '@/utils/request'
import qs from 'querystring'

export function login(data) {
  return request({
    url: '/connect/token',
    method: 'post',
    headers: {
      'content-type': 'application/x-www-form-urlencoded',
      'Accept-Language': 'zh-Hans,zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6'
    },
    data: qs.stringify(data),
    baseURL: public_config.auth_api
  })
  // return new Promise((resolve, reject) => {
  //   const serv = axios.create({
  //     timeout: 5000 // request timeout
  //   })
  //   serv({
  //     url: public_config.auth_api + '/connect/token',
  //     headers: { 'content-type': 'application/x-www-form-urlencoded',
  //       'Accept-Language': 'zh-Hans,zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6'
  //     },
  //     method: 'post',
  //     data: qs.stringify(data)
  //   }).then(res => {
  //     console.log('执行了一次token请求')
  //     if (res.status === 200) {
  //       commit('SET_TOKEN', res.data.access_token)
  //       setToken(res.data.access_token)
  //       resolve(res.data.access_token)
  //     } else {
  //       reject('Error')
  //     }
  //   }, err => {
  //     reject(err)
  //   })
  // }
}

export function getInfo() {
  return request({
    url: '/api/account/my-profile',
    method: 'get',
    baseURL: public_config.configuration_api
  })
}

export function logout() {
  // return request({
  //   // url: '/vue-element-admin/user/logout',
  //   url: '/user/logout',
  //   method: 'post'
  // })
  return request({
    url: '/api/account/logout',
    method: 'get',
    baseURL: public_config.auth_api
  })
}

export function changePassWord(data) {
  return request({
    url: '/api/account/my-profile/change-password',
    method: 'post',
    baseURL: public_config.configuration_api,
    data
  })
}

export function getLoginLog(params) {
  return request({
    url: '/api/app/login-log',
    method: 'get',
    baseURL: public_config.labor_api,
    params
  })
}
/**
 * 登录日志添加
 * @param {*} data
 * @returns
 */
export function insertLognLog(data) {
  return request({
    url: '/api/Export/AddLoginLog',
    method: 'post',
    baseURL: public_config.labor_api,
    data
  })
}
